﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using F_MODEL;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace F_DAL
{

    public class DaiPiPei_dal
    {
        string ConnectionSting = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
        /// <summary>
        /// 待带货匹配
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="mailStatus"></param>
        /// <returns></returns>
        public List<Mails> GetDaiPiPei(int userid, int mailStatus)
        {
            SqlParameter[] sql ={
                               new SqlParameter("@Userid",userid),
                               new SqlParameter("@mailStatus",mailStatus)
                               };
            SqlDataReader reader = DbHelperSQL.RunProcedure("Pro_DaiPiPei", sql);
            List<Mails> getmails = new List<Mails>();
            while (reader.Read())
            {
                Mails mails = new Mails();
                mails.dweight = reader["dweight"].ToString();
                mails.mailId = reader["mailId"].ToString();
                mails.mailStatus = Convert.ToInt32(reader["mailStatus"]);
                mails.Userid = Convert.ToInt32(reader["Userid"]);
                mails.types1 = reader["types1"].ToString();
                getmails.Add(mails);
            }
            return getmails;
            
        }
        /// <summary>
        /// 带货信息
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="mailId"></param>
        /// <returns></returns>
        public  int pipei(int UserId,string mailId)
        {
            //SqlParameter[] par ={
            //                new SqlParameter("@Userid",SqlDbType.Int){Value=UserId},
            //                 new SqlParameter("@mailId",SqlDbType.VarChar){Value=mailId},
            //                   new SqlParameter("@sl",SqlDbType.Int)
            //                };
            

            // Convert.ToInt32(DbHelperSQL.RunProcedureReturnSingle("Pro_DaiDaiHuoPiPei", par));

            // int s = Convert.ToInt32(par[2].Direction  = System.Data.ParameterDirection.Output);
            // return s;
             //连接数据库
             SqlConnection conn = new SqlConnection(ConnectionSting);
             SqlCommand command = new SqlCommand("Pro_DaiDaiHuoPiPei", conn);//执行存储过程
             //-----------------------注意这一段--------------------------------------------------------------------------------------------------------
             SqlParameter p1 = new SqlParameter("@Userid", System.Data.SqlDbType.VarChar);
             p1.Value = UserId;
             SqlParameter p2 = new SqlParameter("@mailId", System.Data.SqlDbType.VarChar);
             p2.Value = mailId;
             SqlParameter p4 = new SqlParameter("@mailStatus", System.Data.SqlDbType.Int);
             p4.Value = 2;
             SqlParameter p3 = new SqlParameter("@sl", System.Data.SqlDbType.Int);
             p3.Direction = System.Data.ParameterDirection.Output;
             command.Parameters.Add(p1);
             command.Parameters.Add(p2);
             command.Parameters.Add(p3);
             command.Parameters.Add(p4);
             command.CommandType = System.Data.CommandType.StoredProcedure;
             //-------------------------------------------------------------------------------------------------------------------------------

             conn.Open();//打开数据连接
             command.ExecuteScalar();
             int sign = Convert.ToInt32(p3.Value);

             conn.Close();
             return sign;//返回单条记录
        }
        /// <summary>
        /// 带货信息
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="mailId"></param>
        /// <returns></returns>
        public int wancheng(int UserId, string mailId)
        {
            //SqlParameter[] par ={
            //                new SqlParameter("@Userid",SqlDbType.Int){Value=UserId},
            //                 new SqlParameter("@mailId",SqlDbType.VarChar){Value=mailId},
            //                   new SqlParameter("@sl",SqlDbType.Int)
            //                };


            // Convert.ToInt32(DbHelperSQL.RunProcedureReturnSingle("Pro_DaiDaiHuoPiPei", par));

            // int s = Convert.ToInt32(par[2].Direction  = System.Data.ParameterDirection.Output);
            // return s;
            //连接数据库
            SqlConnection conn = new SqlConnection(ConnectionSting);
            SqlCommand command = new SqlCommand("Pro_DaiDaiHuoPiPei", conn);//执行存储过程
            //-----------------------注意这一段--------------------------------------------------------------------------------------------------------
            SqlParameter p1 = new SqlParameter("@Userid", System.Data.SqlDbType.VarChar);
            p1.Value = UserId;
            SqlParameter p2 = new SqlParameter("@mailId", System.Data.SqlDbType.VarChar);
            p2.Value = mailId;
            SqlParameter p4 = new SqlParameter("@mailStatus", System.Data.SqlDbType.Int);
            p4.Value = 3;
            SqlParameter p3 = new SqlParameter("@sl", System.Data.SqlDbType.Int);
            p3.Direction = System.Data.ParameterDirection.Output;
            command.Parameters.Add(p1);
            command.Parameters.Add(p2);
            command.Parameters.Add(p3);
            command.Parameters.Add(p4);
            command.CommandType = System.Data.CommandType.StoredProcedure;
            //-------------------------------------------------------------------------------------------------------------------------------

            conn.Open();//打开数据连接
            command.ExecuteScalar();
            int sign = Convert.ToInt32(p3.Value);

            conn.Close();
            return sign;//返回单条记录
        }

       


    }
}
